package hot100;

import comment.ListNode;

import java.util.HashSet;

/**
 * @Author: wzp
 * @CreateTime: 2024-09-24  08:21
 * @Description: 环形链表
 * @Version: 1.0
 */
public class hot_141 {
    public boolean hasCycle(ListNode head) {
        if(head==null||head.next==null){
            return false;
        }
        HashSet<ListNode> hashSet=new HashSet<>();
        boolean tf=false;
        while (head.next!=null){
            if(hashSet.contains(head)){
                tf=true;
                break;
            }
            hashSet.add(head);
            head=head.next;
        }
        return tf;
    }
}
